﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
//MicroDesigner
using Jc.MicroDesigner.Objects;
using Jc.MicroDesigner.Management;

namespace Jc.MicroDesigner.Drawings.Tools
{
    /// <summary>
    /// Инструмент для сложных элементов схемы
    /// </summary>
    public class CompositeTool : DrawingTool
    {
        string _ConfigFile = "";

        /// <summary>
        /// Создать элемент на основе конфига
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="config"></param>
        public CompositeTool(ObjectManager manager, string config) 
        {
            _ConfigFile = config;
            this._Name = CircuitElement.AnalyzeConfig(manager, config);
            this._ToolCursor = Cursors.Cross;
            this.Category = "Микросхемы";
        }

        /// <summary>
        /// Создать объект по клику мыши на холсте
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawPanel panel, MouseEventArgs e)
        {
            if ((panel.ObjManager != null) && (panel.ObjManager != null))
            {
                CircuitElement element = new CompositeElement(panel.ObjManager, _ConfigFile);
                if (panel.Discreteness > 0)
                {
                    Point d = panel.GetDiscreetCoord(e.Location);
                    element.DrawOptions.Top = d.Y;
                    element.DrawOptions.Left = d.X;
                }
                else
                {
                    element.DrawOptions.Left = e.X;
                    element.DrawOptions.Top = e.Y;
                }
                element.Name = panel.ObjManager.NewElementName(element.Name);
                panel.ObjManager.Elements.Add(element);
                panel.Invalidate();
            }
        }
    }
}